package cn.example.litepaltest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import org.litepal.tablemanager.Connector;

import cn.example.litepaltest.entiy.Book;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button btn_create;
    private Button btn_add;
    private Button btn_update;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        btn_create=findViewById(R.id.btn_create);
        btn_add=findViewById(R.id.btn_add);
        btn_update=findViewById(R.id.btn_add);
        btn_create.setOnClickListener(this);
        btn_add.setOnClickListener(this);
        btn_update.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.button:
                Connector.getDatabase();//创建数据库
                break;
            case R.id.btn_add:
                Book book=new Book();// 增加数据
                book.setAuthor("郭霖");
                book.setPages(545);
                book.setName("第一行代码");
                book.setPrice(54.5);
                book.setPress("图灵出版社");
                book.save();
                break;
            case R.id.btn_update:
                Book book1=new Book();
                book1.setAuthor("徐宜生");
                book1.setPages(436);
                book1.setName("Android群英传");
                book1.setPrice(43.6);
                book1.setPress("图灵出版社");
                book1.save();
                book1.setPrice(38.6);
                book1.save();
                break;
        }
    }
}
